<?php


namespace app\dao\car;


use app\dao\BaseDao;
use app\model\car\CarBlacklist;

class CarBlacklistDao extends BaseDao
{
    protected function setModel(): string
    {
        return CarBlacklist::class;
    }

    /**
     * 列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param bool $is_page
     * @return array
     */
    public function getList(array $where = [],int $page = 1,int $limit = 0,bool $is_page = false){
        $model = $this->getModel()->alias('b')->where(['b.is_del'=>0]);
        $model = $model->field('b.*');
        $model = $this->setWheres($model,$where);
        $count = $model->count();
        if($is_page) $model = $model->page($page,$limit);
        $list = $model->order('b.id desc')->select()->toArray();
        return compact('list','count');
    }

    /**
     * 搜索条件
     * @param $model
     * @param $where
     * @return mixed
     */
    public function setWheres($model,$where){
        if(isset($where['keyword']) && $where['keyword']){
            $model->where('a.title','like',"%{$where['keyword']}%");
        }
        return $model;
    }
}
